package cn.qzbook.dao.oneToOne;

import cn.qzbook.MybatisTool;
import cn.qzbook.domain.Person;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class PersonDao {

    private SqlSession sqlSession = MybatisTool.sqlSessionFactory().openSession(true);

    //根据一个人的pid，查询人+身份证的所有信息
    public void selectOnePerson(int pid){

        Person person = sqlSession.selectOne("selectOnePersonAndIdcard_towSQL", pid);

        System.out.println(person);;
    }

    //全表通查  autoMapping做关联属性映射
    public void selectListPerson(){
        List<Person> psersonList = sqlSession.selectList("selectOnePersonAndIdcard_oneSQL_list");
        System.out.println(psersonList.size() == 0);
        for (Person person : psersonList){
            System.out.println(person);
        }
    }

    //全表通查  resultMap下映射关联属性的子标签association 内部嵌套映射关联属性的属性与表字段
    public void selectListPersonAssociationInner(){
        List<Person> psersonList = sqlSession.selectList("selectOnePerson_inner_list");
        System.out.println(psersonList.size() == 0);
        for (Person person : psersonList){
            System.out.println(person);
        }
    }
}
